package com.admin.service.impl;

import com.admin.entity.Address;
import com.admin.mapper.AddressMapper;
import com.admin.service.IAddressService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author marisheng
 * @since 2019-11-21
 */
@Service
public class AddressServiceImpl extends ServiceImpl<AddressMapper, Address> implements IAddressService {
    @Autowired
    private AddressMapper addressMapper;

    /**
     * 新增地址
     *
     * @param address
     * @return
     */
    @Override
    public int add(String address) {

        Address addre = new Address();
        addre.setDetailedAddress(address);
        int n = addressMapper.insert(addre);
        return addre.getAddressId();
    }

    /**
     * 修改详细地址的信息
     *
     * @return
     */
    @Override
    public int updateAddress(String address, int addressId) {
        Address a = new Address();
        a.setDetailedAddress(address);
        if(addressId!=0)
        a.setAddressId(addressId);
        addressMapper.insert(a);
        return a.getAddressId();
    }
}
